#include <iostream>
using namespace std;
class singleton{
public:
    static singleton * getInstance(){
        if(!_ps){
            //在此处注册
            _ps=new singleton();
            atexit(destroy);
        }
        return _ps;
    }
    singleton & operator=(const singleton& rhs)=delete;
    singleton(const singleton& rhs)=delete;
private:
    
    void destroy(){
        //想自动回收
        //atexit是向linux注册一个函数，每当
        //程序结束时候，自动调用
        if(_ps){
            delete _ps;
            _ps=nullptr;
        }
    }    
    singleton(){}
    ~singleton(){}
    static singleton* _ps;

};
    singleton* singleton::_ps=nullptr;

void test(){
    
}
int main(int argc, char * argv[]){
    
    return 0;
}

